Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

Calling C functions from Lua

All of the code that we have written so far has been about exposing C to Lua using Lua Bridge. Any C function exposed through Lua Bridge can be called from Lua. If a function is in a namespace and not a class, it is called with the dot syntax: Math.Sqrt(16). But, if a function is in a class, it needs to be called with the colon syntax: vector:Normalize(). The following code shows how to expose a C function to Lua and how to call it from Lua.

The C code needs to declare the appropriate vector 3 class, a Normalize member function, and a global dot product function. Next, the Register function exposes all of these functions to Lua, using Lua Bridge:

class Vec3 {  public:    float x, y, z;        float Normalize() { float dot ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content