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