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"); }
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"); }
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"); }
static void settagmethod (void) { lua_Object nf = luaL_nonnullarg(3); lua_pushobject(nf); lua_pushobject(lua_settagmethod((int32)luaL_check_number(1), luaL_check_string(2))); }
/* ** Open math library */ void lua_mathlibopen (void) { luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); lua_pushcfunction(math_pow); lua_pushnumber(0); /* to get its tag */ lua_settagmethod(lua_tag(lua_pop()), "pow"); lua_pushnumber(PI); lua_setglobal("PI"); }
/* ** Open math library */ LUALIB_API void lua_mathlibopen (lua_State *L) { luaL_openl(L, mathlib); lua_pushcfunction(L, math_pow); lua_settagmethod(L, LUA_TNUMBER, "pow"); lua_pushnumber(L, PI); lua_setglobal(L, "PI"); }
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"); }
void luaCompat_handleFuncCallEvent(lua_State* L) { /* lua4 */ LUASTACK_SET(L); int tag = lua_tonumber(L, -2); lua_settagmethod(L, tag, "function"); LUASTACK_CLEAN(L, -1); }
void luaCompat_handleNoIndexEvent(lua_State* L) { /* lua4 */ LUASTACK_SET(L); int tag = lua_tonumber(L, -2); lua_settagmethod(L, tag, "index"); LUASTACK_CLEAN(L, -1); }
/* ** Open math library */ void lua_mathlibopen (void) { luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); luaL_addlibtolist(powFunc, (sizeof(powFunc)/sizeof(powFunc[0]))); lua_pushstring("deg"); lua_setglobal("_TRIGMODE"); lua_pushcfunction(math_pow); lua_pushnumber(0); /* to get its tag */ lua_settagmethod(lua_tag(lua_pop()), "pow"); lua_pushnumber(LOCAL_PI); lua_setglobal("PI"); }
static int luaB_settagmethod (lua_State *L) { int tag = luaL_check_int(L, 1); const char *event = luaL_check_string(L, 2); luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3, "function or nil expected"); if (strcmp(event, "gc") == 0) lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua"); lua_gettagmethod(L, tag, event); lua_pushvalue(L, 3); lua_settagmethod(L, tag, event); return 1; }
/* 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; }
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); }
/* 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; }
void CScriptSystem::UnbindUserdata() { lua_pushnil(m_pLS); lua_settagmethod(m_pLS, m_nGCTag, "gc"); }
static void luaB_settagmethod (void) { lua_Object nf = luaL_nonnullarg(3); lua_pushobject(nf); lua_pushobject(lua_settagmethod(luaL_check_int(1), luaL_check_string(2))); }