From 3c616425a1e457b1a4eb7b5fc83ede5b74e79f58 Mon Sep 17 00:00:00 2001 From: James Nurmi Date: Tue, 21 Sep 2010 22:09:43 -0400 Subject: [PATCH] patched to add simple Open{Base,IO,Math,Package,String,Table} methods for more granular environment setup. Signed-off-by: Adam Fitzgerald --- lua51/golua.c | 31 +++++++++++++++++++++++++++++++ lua51/golua.h | 7 +++++++ lua51/lua.go | 25 +++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/lua51/golua.c b/lua51/golua.c index 807e307..ea57652 100644 --- a/lua51/golua.c +++ b/lua51/golua.c @@ -1,5 +1,6 @@ #include #include +#include #include "_cgo_export.h" //metatables to register: @@ -166,3 +167,33 @@ void clua_setallocf(lua_State* L, void* goallocf) { lua_setallocf(L,&allocwrapper,goallocf); } + +void clua_openbase(lua_State* L){ + lua_pushcfunction(L,&luaopen_base); + lua_call(L, 0, 0); +} + +void clua_openio(lua_State* L){ + lua_pushcfunction(L,&luaopen_io); + lua_call(L, 0, 0); +} + +void clua_openmath(lua_State* L){ + lua_pushcfunction(L,&luaopen_math); + lua_call(L, 0, 0); +} + +void clua_openpackage(lua_State* L){ + lua_pushcfunction(L,&luaopen_package); + lua_call(L, 0, 0); +} + +void clua_openstring(lua_State* L){ + lua_pushcfunction(L,&luaopen_string); + lua_call(L, 0, 0); +} + +void clua_opentable(lua_State* L){ + lua_pushcfunction(L,&luaopen_table); + lua_call(L, 0, 0); +} diff --git a/lua51/golua.h b/lua51/golua.h index 8b33e79..0af7602 100644 --- a/lua51/golua.h +++ b/lua51/golua.h @@ -14,6 +14,13 @@ int clua_callluacfunc(lua_State* L, lua_CFunction f); lua_State* clua_newstate(void* goallocf); void clua_setallocf(lua_State* L, void* goallocf); +void clua_openbase(lua_State* L); +void clua_openio(lua_State* L); +void clua_openmath(lua_State* L); +void clua_openpackage(lua_State* L); +void clua_openstring(lua_State* L); +void clua_opentable(lua_State* L); + //TODO: get/set panicf //TODO: get/set allocf diff --git a/lua51/lua.go b/lua51/lua.go index 9f60b60..a040026 100644 --- a/lua51/lua.go +++ b/lua51/lua.go @@ -477,5 +477,30 @@ func Yield(L *State, nresults int) int { return int(C.lua_yield(L.s, C.int(nresults))); } +// Restricted library opens + +func OpenBase(L *State) { + C.clua_openbase(L.s); +} + +func OpenIO(L *State) { + C.clua_openio(L.s); +} + +func OpenMath(L *State) { + C.clua_openmath(L.s); +} + +func OpenPackage(L *State) { + C.clua_openpackage(L.s); +} + +func OpenString(L *State) { + C.clua_openstring(L.s); +} + +func OpenTable(L *State) { + C.clua_opentable(L.s); +}