[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Enigma-cvs] enigma/src lua.cc,1.16,1.17
From: |
Daniel Heck <address@hidden> |
Subject: |
[Enigma-cvs] enigma/src lua.cc,1.16,1.17 |
Date: |
Sun, 16 Nov 2003 18:43:18 +0000 |
Update of /cvsroot/enigma/enigma/src
In directory subversions:/tmp/cvs-serv32144/src
Modified Files:
lua.cc
Log Message:
- Added lua::SetTableVar(), GlobalState(), ShutdownGlobal(),
InitLevel(), ShutdownLevel()
- Removed lua::state
- Only export relevant C functions to global Lua state
Index: lua.cc
===================================================================
RCS file: /cvsroot/enigma/enigma/src/lua.cc,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** lua.cc 23 Oct 2003 20:21:50 -0000 1.16
--- lua.cc 16 Nov 2003 18:43:16 -0000 1.17
***************
*** 47,55 ****
namespace lua
{
! lua_State *state = 0; // global Lua state
int object_tag; // Lua tag for `Object's
ForceField *cff = 0; // constant force field for levels
}
//----------------------------------------------------------------------
// Helper routines
--- 47,60 ----
namespace lua
{
! lua_State *LevelState = 0; // level-local state
int object_tag; // Lua tag for `Object's
ForceField *cff = 0; // constant force field for levels
}
+ namespace
+ {
+ lua_State *global_state = 0; // global Lua state
+ }
+
//----------------------------------------------------------------------
// Helper routines
***************
*** 58,61 ****
--- 63,79 ----
using enigma::Value;
+ void lua::SetTableVar (lua_State *L,
+ const char *tablename,
+ const char *name,
+ double value)
+ {
+ lua_getglobal (L, tablename);
+ lua_pushstring (L, name);
+ lua_pushnumber (L, value);
+ lua_rawset (L, -3);
+ lua_pop (L, 1);
+ }
+
+
static void
push_value(lua_State *L, const Value &val)
***************
*** 114,120 ****
}
! //----------------------------------------------------------------------
! // Enigma interface routines
! //----------------------------------------------------------------------
static int
en_make_object (lua_State *L)
--- 132,138 ----
}
!
! /* -------------------- Interface routines -------------------- */
!
static int
en_make_object (lua_State *L)
***************
*** 332,337 ****
}
- // LUA functions
-
int lua::FindDataFile(lua_State *L)
{
--- 350,353 ----
***************
*** 419,427 ****
}
! static CFunction luafuncs[] = {
// internal functions
! {lua::FindDataFile, "FindDataFile"},
{get_object_template, "GetObjectTemplate"},
{en_make_object, "MakeObject"},
--- 435,449 ----
}
! static CFunction globalfuncs[] = {
! {FindDataFile, "FindDataFile"},
! {en_play_sound, "PlaySound"},
! {get_ticks, "GetTicks"},
! };
!
! static CFunction levelfuncs[] = {
// internal functions
! {FindDataFile, "FindDataFile"},
{get_object_template, "GetObjectTemplate"},
{en_make_object, "MakeObject"},
***************
*** 474,555 ****
//----------------------------------------------------------------------
! void lua::RegisterFuncs(CFunction *funcs)
{
! lua_getglobal(state, "enigma");
for (unsigned i=0; funcs[i].func; ++i) {
! lua_pushstring(state, funcs[i].name);
! lua_pushcfunction(state, funcs[i].func);
! lua_settable(state, -3);
}
! lua_pop(state, 1);
}
! int
! lua::CallFunc(const char *funcname, const Value& arg)
{
! lua_getglobal(state, funcname);
! push_value(state, arg);
! return lua_call(state, 1, 0);
}
! int lua::Dofile(const string &filename)
{
string fname = enigma::FindDataFile(filename);
! int oldtop = lua_gettop(state);
! int retval = lua_dofile(state, fname.c_str());
! lua_settop(state, oldtop);
return retval;
}
! int lua::Dobuffer (const vector<char> &luacode)
{
! return lua_dobuffer (state, &luacode[0], luacode.size(), "buffer");
}
int
! lua::DoSubfolderfile(const string &basefolder, const string &filename)
{
std::list <string> fnames = enigma::FindDataFiles(basefolder, filename);
int retval = 0;
! while ( fnames.size() > 0)
{
! int oldtop = lua_gettop(state);
string fname = fnames.front();
! retval = lua_dofile(state, fname.c_str());
fnames.pop_front();
! lua_settop(state, oldtop);
}
return retval;
}
! void
! lua::Init()
! {
! state = lua_open(0);
! lua_baselibopen(state);
! lua_strlibopen(state);
! lua_mathlibopen(state);
! lua_iolibopen(state);
! tolua_open(state);
! tolua_enigma_open(state);
! tolua_px_open(state);
! tolua_display_open(state);
// Create a new tag for world::Object objects
! object_tag = lua_newtag(state);
- // Register all functions
- RegisterFuncs(luafuncs);
cff = 0;
}
! void lua::Shutdown()
{
! if (state) {
! lua_close(state);
! state = 0;
if (cff) {
delete cff;
--- 496,604 ----
//----------------------------------------------------------------------
! void lua::RegisterFuncs(lua_State *L, CFunction *funcs)
{
! lua_getglobal(L, "enigma");
for (unsigned i=0; funcs[i].func; ++i) {
! lua_pushstring(L, funcs[i].name);
! lua_pushcfunction(L, funcs[i].func);
! lua_settable(L, -3);
}
! lua_pop(L, 1);
}
! int lua::CallFunc(lua_State *L, const char *funcname, const Value& arg)
{
! lua_getglobal(L, funcname);
! push_value(L, arg);
! return lua_call(L, 1, 0);
}
! int lua::Dofile(lua_State *L, const string &filename)
{
string fname = enigma::FindDataFile(filename);
! int oldtop = lua_gettop(L);
! int retval = lua_dofile(L, fname.c_str());
! lua_settop(L, oldtop);
return retval;
}
! int lua::Dobuffer (lua_State *L, const vector<char> &luacode)
{
! return lua_dobuffer (L, &luacode[0], luacode.size(), "buffer");
}
int
! lua::DoSubfolderfile(lua_State *L, const string &basefolder, const string
&filename)
{
std::list <string> fnames = enigma::FindDataFiles(basefolder, filename);
int retval = 0;
! while (fnames.size() > 0)
{
! int oldtop = lua_gettop(L);
string fname = fnames.front();
! retval = lua_dofile(L, fname.c_str());
fnames.pop_front();
! lua_settop(L, oldtop);
}
return retval;
}
! static void init_global() {
! lua_State *L = global_state = lua_open(0);
! lua_baselibopen(L);
! lua_strlibopen(L);
! lua_mathlibopen(L);
! lua_iolibopen(L);
!
! tolua_open(L);
! tolua_enigma_open(L);
!
! RegisterFuncs(L, globalfuncs);
! }
!
! lua_State *lua::GlobalState() {
! if (global_state == 0)
! init_global();
! return global_state;
! }
!
! lua_State *lua::InitLevel() {
! lua_State *L = LevelState = lua_open(0);
!
! lua_baselibopen(L);
! lua_strlibopen(L);
! lua_mathlibopen(L);
! lua_iolibopen(L);
!
! tolua_open(L);
! tolua_enigma_open(L);
! tolua_px_open(L);
! tolua_display_open(L);
!
! RegisterFuncs(L, levelfuncs);
// Create a new tag for world::Object objects
! object_tag = lua_newtag(L);
cff = 0;
+
+ return L;
}
! void lua::ShutdownGlobal()
{
! assert (global_state);
! lua_close(global_state);
! global_state = 0;
! }
!
! void lua::ShutdownLevel()
! {
! if (LevelState) {
! lua_close(LevelState);
! LevelState = 0;
if (cff) {
delete cff;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Enigma-cvs] enigma/src lua.cc,1.16,1.17,
Daniel Heck <address@hidden> <=
- Prev by Date:
[Enigma-cvs] enigma/src main.cc,1.23,1.24
- Next by Date:
[Enigma-cvs] enigma/src d_models.hh, 1.11, 1.12 d_models.cc, 1.15, 1.16
- Previous by thread:
[Enigma-cvs] enigma/src main.cc,1.23,1.24
- Next by thread:
[Enigma-cvs] enigma/src d_models.hh, 1.11, 1.12 d_models.cc, 1.15, 1.16
- Index(es):