【Lua】組み込み系言語総合 その4【Squirrel】
■ このスレッドは過去ログ倉庫に格納されています
0232デフォルトの名無しさん
2011/06/11(土) 21:10:20.97>>231
出来るよ。
int call_lua_function(lua_State *L) {
if( lua_gettop(L)>=1 && lua_type(L,-1) == LUA_TFUNCTION ) {
lua_pcall(L, 0, LUA_MULTRET, 0);
}
return 0;
}
int call_c_function(lua_State *L) {
void (*pCFunction)();
if( lua_gettop(L)>=1 && lua_type(L,-1) == LUA_TLIGHTUSERDATA ) {
pCFunction = (void(*)()) lua_topointer(L,-1);
pCFunction();
}
return 0;
}
void HelloWorld() { printf("Hello C Function!\n"); }
int get_c_function(lua_State *L) {
lua_pushlightuserdata(L, (void*)&HelloWorld);
return 1;
}
-- test.lua
call_lua_function( function() print("Hello Lua Function") end )
call_c_function(get_c_function())
■ このスレッドは過去ログ倉庫に格納されています