Beispiel #1
0
/*
28_2.lua
与28_1.lua相同只是输出结果会报错
a = array.new(1000)
print(a)
print(array.size(a))
for i=1,1000 do
    array.set(a,i,i%5==0)
end
print(array.get(io.stdin,10))
print(array.get(a,11))
*/
void test28_2(lua_State *L)
{
	luaopen_array(L);
	
	if(luaL_loadfile(L, "28_4_1.lua") || lua_pcall(L, 0, 0, 0))	// "28_2.lua"
		printf("cannot run config. file:%s\n", lua_tostring(L, -1));
}
Beispiel #2
0
void load(const char *filename)
{
	lua_State *L = luaL_newstate();
	luaL_openlibs(L); /* opens the libs. */
	luaopen_array(L);	// 注册自定义的函数
	if (luaL_loadfile(L, filename) || lua_pcall(L, 0, 0, 0))
		errorf(L, "cannot run app file: %s", lua_tostring(L, -1));
	lua_close(L);
}
Beispiel #3
0
//测试以不同方式注册函数
void test4()
{
	lua_State *L = luaL_newstate();
	luaL_openlibs(L);
	luaopen_array(L);
	//luaopen_array_new(L);
	if (luaL_loadfile(L, "test.lua") || lua_pcall(L, 0, 0, 0))
	{
		error(L, "cannot run configuration file: %s", lua_tostring(L, -1));
	}
	lua_close(L);
}