Source: src/si_wrapper.cc
|
|
|
|
#include "si_wrapper.h"
int lget_int(lua_State *lstate, char *name)
{
int sp, r, i;
sp = lua_gettop(lstate);
lua_getglobal(lstate, name);
r=lua_gettop(lstate);
i =(int) lua_tonumber(lstate, r);
lua_settop(lstate, sp);
return i;
}
const char *lget_str(lua_State *lstate, char *name)
{
int sp, r;
const char *i;
sp = lua_gettop(lstate);
lua_getglobal(lstate, name);
r = lua_gettop(lstate);
i = lua_tostring(lstate, r);
lua_settop(lstate, sp);
return i;
}
const char *lget_str(lua_State *lstate, char *name, int index)
{
int sp, r;
const char *i;
sp = lua_gettop(lstate);
lua_getglobal(lstate, name);
r = lua_gettop(lstate);
lua_rawgeti(lstate, r, index);
r = lua_gettop(lstate);
i = lua_tostring(lstate, r);
lua_settop(lstate, sp);
return i;
}
void get_array(lua_State *lstate, deque &l)
{
int sp;
l.clear();
sp = lua_gettop(lstate);
lua_pushnil(lstate);
while(lua_next(lstate, sp) != 0 )
{
l.push_back(lua_tostring(lstate, LUA_VALUE));
lua_pop(lstate,1);
}
lua_pop(lstate,1);
}
void get_table(lua_State *lstate, map < string, int > &numbers, map< string, string > &strings,
map > &tables)
{
int t, type;
int sp;
deque l;
string q,key;
t = lua_gettop(lstate);
lua_pushnil(lstate);
while(lua_next(lstate, t) != 0) {
type =(int)lua_type(lstate, LUA_VALUE);
switch(type) {
case LUA_STRING : {
strings[lua_tostring(lstate, LUA_KEY)]
= lua_tostring(lstate, LUA_VALUE);
break;
}
case LUA_NUMBER : {
numbers[lua_tostring(lstate, LUA_KEY)]
= (int)lua_tonumber(lstate, LUA_VALUE);
break;
}
case LUA_TABLE : {
l.clear();
key = lua_tostring(lstate, LUA_KEY);
#ifdef HARD_DEBUG
message("Loading table [%s]",key.c_str());
#endif
sp = lua_gettop(lstate);
lua_pushnil(lstate);
while(lua_next(lstate, sp) != 0 ) {
q=lua_tostring(lstate, LUA_VALUE);
l.push_back(q);
#ifdef HARD_DEBUG
message("cycle[%s]",q.c_str());
#endif
lua_pop(lstate,1);
}
tables[key] = l;
break;
}
default : {
message("Uknown Lua type [%i]",type);
}
}
lua_pop(lstate, 1);
}
lua_pop(lstate, 1); //pops the end of table
message("Table succesfully loaded");
}
void get_table(lua_State *lstate, map < string, int > &numbers, map< string, string > &strings)
{
map < string, deque > tables;
get_table(lstate, numbers, strings, tables);
}
const char *lget_arg_str(lua_State *lstate)
{
int t;
const char *c;
t = lua_gettop(lstate);
c = lua_tostring(lstate, t);
lua_pop(lstate, 1);
return c;
}
int lget_arg_int(lua_State *lstate)
{
int t;
int c;
t = lua_gettop(lstate);
c = (int)lua_tonumber(lstate, t);
lua_pop(lstate, 1);
return c;
}
int lpanic (lua_State *L)
{
message("Error: Lua get panic!");
return 0;
}
int lget_argc(lua_State *lstate)
{
return (int)lua_gettop(lstate);
}
Generated by: georgik on armada on Sat Jul 24 07:07:15 2004, using kdoc 2.0a54. |