lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Leinen, Rick once stated:
> 
> I'm still working on proof-of-concept on my project and currently do not
> have a file system in place on my target.  Registering the new library
> worked just fine, but when I enter, array = require "arraylib", from my
> shell interface I get the following response:

  Assuming the C code for arraylib is linked into the overall program, then
you can do:

	lua_State *L;

	L = luaL_newstate();		/* or however you create them	*/
	luaL_openlibs(L);		/* standard Lua modules 	*/

	/*---------------------------------------------------------------
	; the following does:
	;
	; package.preload['arraylib'] = init_function
	;
	; Doing this will allow require() to locate the initialization
	; routine for "arraylib" so it can be called and allow arraylib to
	; be loaded into Lua for use.
	;---------------------------------------------------------------*/

	lua_getglobal(L,"package");
	lua_getfield(L,-1,"preload");
	lua_pushcfunction(L,luaopen_arraylib);
	lua_setfield(L,-2,"arraylib");

  -spc