Esempio n. 1
0
static void openwithcontrol (lua_State *L) {
  IOCtrl *ctrl = (IOCtrl *)lua_newuserdata(L, sizeof(IOCtrl));
  unsigned int i;
  ctrl->iotag = lua_newtag(L);
  ctrl->closedtag = lua_newtag(L);
  for (i=0; i<sizeof(iolibtag)/sizeof(iolibtag[0]); i++) {
    /* put `ctrl' as upvalue for these functions */
    lua_pushvalue(L, -1);
    lua_pushcclosure(L, iolibtag[i].func, 1);
    lua_setglobal(L, iolibtag[i].name);
  }
  /* create references to variable names */
  lua_pushstring(L, filenames[INFILE]);
  ctrl->ref[INFILE] = lua_ref(L, 1);
  lua_pushstring(L, filenames[OUTFILE]);
  ctrl->ref[OUTFILE] = lua_ref(L, 1);
  /* predefined file handles */
  setfile(L, ctrl, stdin, INFILE);
  setfile(L, ctrl, stdout, OUTFILE);
  setfilebyname(L, ctrl, stdin, "_STDIN");
  setfilebyname(L, ctrl, stdout, "_STDOUT");
  setfilebyname(L, ctrl, stderr, "_STDERR");
  /* close files when collected */
  lua_pushcclosure(L, file_collect, 1);  /* pops `ctrl' from stack */
  lua_settagmethod(L, ctrl->iotag, "gc");
}
Esempio n. 2
0
static void openwithtags() {
	int32 iotag = lua_newtag();
	int32 closedtag = lua_newtag();
	uint32 i;
	for (i = 0; i < sizeof(iolibtag) / sizeof(iolibtag[0]); i++) {
		// put both tags as upvalues for these functions
		lua_pushnumber(iotag);
		lua_pushnumber(closedtag);
		lua_pushCclosure(iolibtag[i].func, 2);
		lua_setglobal(iolibtag[i].name);
	}

	g_fin = new LuaFile();
	g_fin->_stdin = true;
	setfile(addfile(g_fin), FINPUT, iotag);

	g_fout = new LuaFile();
	g_fout->_stdout = true;
	setfile(addfile(g_fout), FOUTPUT, iotag);

	g_stdin = new LuaFile();
	g_stdin->_stdin = true;
	setfile(addfile(g_stdin), "_STDIN", iotag);

	g_stdout = new LuaFile();
	g_stdout->_stdout = true;
	setfile(addfile(g_stdout), "_STDOUT", iotag);

	g_stderr = new LuaFile();
	g_stderr->_stderr = true;
	setfile(addfile(g_stderr), "_STDERR", iotag);
}
Esempio n. 3
0
void CScriptSystem::RegisterTagHandlers()
{
    m_nGCTag = lua_newtag(m_pLS);
    lua_pushlightuserdata(m_pLS, NULL);
    lua_pushcclosure(m_pLS, GCTagHandler, 1);
    lua_settagmethod(m_pLS, m_nGCTag, "gc");
}
Esempio n. 4
0
void toluaI_tt_init (lua_State* L)
{
 lua_newtable(L); toluaI_setregistry(L,"tolua_tbl_itype");
 lua_newtable(L); toluaI_setregistry(L,"tolua_tbl_itag");
 lua_newtable(L); toluaI_setregistry(L,"tolua_tbl_const");
 lua_newtable(L); toluaI_setregistry(L,"tolua_tbl_hierarchy");

 /* set and register basic Lua type tag */
#if 0
 lua_pushnumber(L,LUA_TNIL); toluaI_setregistry(L,"tolua_tag_nil");
 lua_pushnumber(L,LUA_TNUMBER); toluaI_setregistry(L,"tolua_tag_number");
 lua_pushnumber(L,LUA_TSTRING); toluaI_setregistry(L,"tolua_tag_string");
 lua_pushnumber(L,LUA_TUSERDATA); toluaI_setregistry(L,"tolua_tag_userdata");
 lua_pushnumber(L,LUA_TTABLE); toluaI_setregistry(L,"tolua_tag_table");
 lua_pushnumber(L,LUA_TFUNCTION); toluaI_setregistry(L,"tolua_tag_function");
 
 toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_nil"),"nil");
 toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_number"),"number");
 toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_string"),"string");
 toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_userdata"),"userdata");
 toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_table"),"table");
 toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_function"),"function");
#else
 toluaI_tt_register(L,LUA_TNIL,"nil");
 toluaI_tt_register(L,LUA_TNUMBER,"number");
 toluaI_tt_register(L,LUA_TSTRING,"string");
 toluaI_tt_register(L,LUA_TUSERDATA,"userdata");
 toluaI_tt_register(L,LUA_TTABLE,"table");
 toluaI_tt_register(L,LUA_TFUNCTION,"function");
 toluaI_tt_register(L,lua_newtag(L),"bool");
#endif
}
Esempio n. 5
0
void if2_lua_scanner::register_type( lua_State *L )
{
  otag = lua_newtag( L );
  lua_pushcfunction( L, destructor );
  lua_settagmethod( L, otag, "gc" );
  lua_pushcfunction(L,constructor );
  lua_setglobal(L,"if2_scanner");
}
Esempio n. 6
0
File: liolib.c Progetto: jeske/hz
static void openwithtags (void)
{
  int iotag = lua_newtag();
  int closedtag = lua_newtag();
  int i;
  for (i=0; i<sizeof(iolibtag)/sizeof(iolibtag[0]); i++) {
    /* put both tags as upvalues for these functions */
    lua_pushnumber(iotag);
    lua_pushnumber(closedtag);
    lua_pushCclosure(iolibtag[i].func, 2);
    lua_setglobal(iolibtag[i].name);
  }
  setfile(stdin, FINPUT, iotag);
  setfile(stdout, FOUTPUT, iotag);
  setfile(stdin, "_STDIN", iotag);
  setfile(stdout, "_STDOUT", iotag);
  setfile(stderr, "_STDERR", iotag);
}
Esempio n. 7
0
/* Register module */
LUA_API int luaopen_python(lua_State *L) {
    lua_Object python = lua_createtable(L);

    set_table_string(L, python, PY_UNICODE_ENCODING, "utf8");
    set_table_string(L, python, PY_UNICODE_ENCODING_ERRORHANDLER, "strict");
    set_table_number(L, python, PY_OBJECT_BY_REFERENCE, 0);
    set_table_number(L, python, PY_API_IS_EMBEDDED, 0);  // If Python is inside Lua
    set_table_number(L, python, PY_LUA_TABLE_CONVERT, 0); // table convert ?

    lua_pushcfunction(L, py_args);
    lua_setglobal(L, PY_ARGS_FUNC);

    lua_pushcfunction(L, py_kwargs);
    lua_setglobal(L, PY_KWARGS_FUNC);

    lua_pushcfunction(L, py_args_array);
    lua_setglobal(L, PY_ARGS_ARRAY_FUNC);

    lua_pushobject(L, python);
    lua_setglobal(L, PY_API_NAME);  // api python

    int index = 0;
    while (py_lib[index].name) {
        set_table_fn(L, python, py_lib[index].name, py_lib[index].func);
        index++;
    }

    // register all tag methods
    int ntag = lua_newtag(L);
    index = 0;
    while (lua_tag_methods[index].name) {
        lua_pushcfunction(L, lua_tag_methods[index].func);
        lua_settagmethod(L, ntag, lua_tag_methods[index].name);
        index++;
    }

    // tag event
    set_table_number(L, python, PY_API_TAG, ntag);

    PyObject *pyObject = Py_True;
    Py_INCREF(pyObject);
    set_table_usertag(L, python, PY_TRUE, py_object_container(L, pyObject, 0), ntag);

    pyObject = Py_False;
    Py_INCREF(pyObject);
    set_table_usertag(L, python, PY_FALSE, py_object_container(L, pyObject, 0), ntag);

    pyObject = Py_None;
    Py_INCREF(pyObject);
    set_table_usertag(L, python, PY_NONE, py_object_container(L, pyObject, 0), ntag);
    return 0;
}
Esempio n. 8
0
void tolua_usertype (lua_State* L, const char* type)
{
 /* check if type is already registered */
 toluaI_getregistry(L,"tolua_tbl_itag");
 lua_pushstring(L,type);
 lua_gettable(L,-2);
 if (lua_isnil(L,-1))
 {
  char *ctype = toluaI_tt_concat("const ",type);
  int tag = lua_newtag(L);
  int ctag = lua_newtag(L);
  toluaI_tt_register(L,tag,type);
  toluaI_tt_register(L,ctag,ctype);
  /* set const table */
  toluaI_getregistry(L,"tolua_tbl_const");
  lua_pushnumber(L,ctag); 
  lua_pushnumber(L,tag); 
  lua_settable(L,-3);
  lua_pop(L,1);
 }
 lua_pop(L,2);
}
Esempio n. 9
0
void tolua_class (lua_State* L, int derived, int base)
{
 int tag = lua_newtag(L);    /* new tag of instances of that class */
 toluaI_tm_setclass(L,derived);
 toluaI_tm_linstance(L,tag,derived);
 lua_pushvalue(L,derived);
 lua_pushstring(L,".base");
 lua_pushvalue(L,base);
 lua_rawset(L,-3); 
 lua_pushstring(L,".itag");
 lua_pushnumber(L,tag);
 lua_rawset(L,-3);
 lua_pop(L,1);
}
Esempio n. 10
0
void luaCompat_newLuaType(lua_State* L,
                           const char* module_name,
                           const char* type_name)
{ /* lua4 */
  LUASTACK_SET(L);

  int tag = lua_newtag(L);

  lua_pushnumber(L, tag);

  luaCompat_moduleSet(L, module_name, type_name);

  LUASTACK_CLEAN(L, 0);
}
Esempio n. 11
0
void tolua_globalarray (lua_State* L, const char* name, lua_CFunction get, lua_CFunction set)
{
 int tag = lua_newtag(L);
 lua_newtable(L);
 lua_settag(L,tag);
 lua_setglobal(L,name);
 
 lua_pushcfunction(L,get);
 lua_settagmethod(L,tag,"gettable"); 
 if (set)
  lua_pushcfunction(L,set);
 else
  lua_pushcfunction(L,toluaI_const_global_array);
 lua_settagmethod(L,tag,"settable");
}
Esempio n. 12
0
void tolua_tablearray
(lua_State* L, const char* table, const char* name, lua_CFunction get, lua_CFunction set)
{
 int tag = lua_newtag(L);
 lua_getglobal(L,table);
 lua_pushstring(L,".array");
 lua_rawget(L,-2);
 lua_pushstring(L,name);
 lua_newtable(L);
 lua_settag(L,tag);
 lua_settable(L,-3);
 lua_pop(L,2);

 lua_pushcfunction(L,get);
 lua_settagmethod(L,tag,"gettable");
 if (set)
  lua_pushcfunction(L,set);
 else
  lua_pushcfunction(L,toluaI_const_array);
 lua_settagmethod(L,tag,"settable");

 tolua_tablevar(L,table,name,toluaI_get_array,NULL);
}
Esempio n. 13
0
/* Register module */
LUA_API int luaopen_python(lua_State *L) {
    lua_Object python = lua_createtable(L);

    lua_pushobject(L, python);
    lua_setglobal(L, "python");  // api python

    int index = 0;
    while (py_lib[index].name) {
        set_table_fn(L, python, py_lib[index].name, py_lib[index].func);
        index++;
    }

    set_table_userdata(L, python, "True", Py_True);
    set_table_userdata(L, python, "False", Py_False);

    // base python object
    lua_Object ltable = lua_createtable(L);
    set_table_object(L, python, POBJECT, ltable);

    // register all tag methods
    int ntag = lua_newtag(L);
    index = 0;
    while (lua_tag_methods[index].name) {
        lua_pushcfunction(L, lua_tag_methods[index].func);
        lua_settagmethod(L, ntag, lua_tag_methods[index].name);
        index++;
    }

    // set tag
    lua_pushobject(L, ltable);
    lua_settag(L, ntag);

    // try startup system
    // python_system_init(L);
    return 0;
}
Esempio n. 14
0
static void newtag() {
	lua_pushnumber(lua_newtag());
}
Esempio n. 15
0
static void luaB_newtag (void) {
  lua_pushnumber(lua_newtag());
}
Esempio n. 16
0
int iuplua_open(void)
{
  struct FuncList {
    char *name;
    lua_CFunction func;
  } FuncList[] = {
    { "IupSetIdle", IupSetIdle },
  };
  int SizeFuncList = (sizeof(FuncList)/sizeof(struct FuncList));
  int i;

  iuplua_tag = lua_newtag();
  lua_pushnumber(iuplua_tag);
  lua_setglobal("iuplua_tag");

  iuplua_namespace = lua_createtable();
  lua_pushobject(iuplua_namespace); lua_setglobal ("iup");

  setinfo();

  for (i = 0; i < SizeFuncList; i++)
    iuplua_register(FuncList[i].name, FuncList[i].func);

  lua_register("iup_gettable", iuplua_gettable);
  lua_register("iup_settable", iuplua_settable);
  lua_register("iup_index", iuplua_index);
  lua_register("iupSetCallback", iuplua_set_callback);

  iupKeyForEach(register_key, NULL);

  iupluaapi_open();

#ifdef IUPLUA_USELOH
#ifdef TEC_BIGENDIAN
#ifdef TEC_64
#include "loh/iuplua_be64.loh"
#include "loh/constants_be64.loh"
#else
#include "loh/iuplua_be32.loh"
#include "loh/constants_be32.loh"
#endif  
#else
#ifdef TEC_64
#ifdef WIN64
#include "loh/iuplua_le64w.loh"
#include "loh/constants_le64w.loh"
#else
#include "loh/iuplua_le64.loh"
#include "loh/constants_le64.loh"
#endif  
#else
#include "loh/iuplua.loh"
#include "loh/constants.loh"
#endif  
#endif  
#else
  iuplua_dofile("iuplua.lua");
  iuplua_dofile("constants.lua");
#endif

  iupluawidgets_open(iuplua_tag);

  sboxlua_open();
  spinlua_open();
  cboxlua_open();
  vallua_open();
  tabslua_open();
  gclua_open();
  getparamlua_open();
  treelua_open();

  return 1;
}
Esempio n. 17
0
static int luaB_newtag (lua_State *L) {
  lua_pushnumber(L, lua_newtag(L));
  return 1;
}