Skip to content

Commit

Permalink
patched to add simple Open{Base,IO,Math,Package,String,Table} methods…
Browse files Browse the repository at this point in the history
… for more granular environment setup.

Signed-off-by: Adam Fitzgerald <afitz@gatech.edu>
  • Loading branch information
James Nurmi authored and afitz committed Sep 22, 2010
1 parent 91b7da9 commit 3c61642
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lua51/golua.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include "_cgo_export.h"

//metatables to register:
Expand Down Expand Up @@ -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);
}
7 changes: 7 additions & 0 deletions lua51/golua.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions lua51/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


0 comments on commit 3c61642

Please sign in to comment.