1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
16 //! Compile and execute Lua code at runtime.
18 A Script represents a self-contained Lua state. It might have
19 variables, functions, statements, and expressions, and can be executed.
20 Each Script lives in a separate memory space and cannot directly
21 access or call other Scripts.
23 On their own, Scripts cannot change anything in a game. Instead, you
24 must bind C functions that they can call. These C functions can access
25 the C++ objects in the game. You might bind a function that makes a
26 player jump, or that returns the distance to the nearest town. You can
27 also bind variables that a script can access.
34 //! Create a new Lua state. The state is destroyed with the death of
38 //! If we already have a Lua state, wrap around it. The state is not
39 //destroyed with the death of this object.
42 //! Destroy the Lua state if we own it.
46 //! Bind a C function to a global variable in Lua.
47 void bindGlobalFn(const char* name
, lua_CFunction fn
);
49 //! Bind a C function to a table index. In Lua: "table.index = fn"
50 void bindObjFn(const char* table
, const char* index
, lua_CFunction fn
);
52 //! Set a global integer variable in Lua.
53 void bindInt(const char* name
, lua_Integer i
);
56 //! Create a global table with specified name which represents an Entity.
57 void bindEntity(const char* name
, Entity
* entity
);
59 //! Get the Entity object from a table in the Lua stack at a specific
61 Entity
* getEntity(int pos
);
64 //! Compile and run a script, keeping all existing bindings intact.
65 void run(const char* fn
);
68 //! Did we create our state, or are we borrowing it from another Script
72 //! Everything necessary to compile and run a Lua script.
73 lua_State
* L
; // TODO: change to shared_ptr ?