I have a simple plugin used to works in very old release, now it's not works, please help me. the line luaL_register (L,"mysolve", func_list); cause it crash when require it in Lua.
static int solve(lua_State *L)
{
.....
return 2;
}
static int generate(lua_State *L)
{
.......
return 2;
}
static int luaopen_solve(lua_State *L)
{
const luaL_Reg func_list[] =
{
{ "solve", solve },
{ "generate", generate },
{NULL, NULL}
};
luaL_register (L,"mysolve", func_list); // this line will not work now.
return 1;
}
static void g_initializePlugin(lua_State *L)
{
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
lua_pushcnfunction(L, luaopen_solve, "plugin_init_mysolve");
lua_setfield(L, -2, "mysolve");
lua_pop(L, 2);
}
Comments
At first sight your code seems to be still compatible with recent gideros. Doesn't it send any meaningful message in Gideros Studio's console ?
Can you try to change the register line like below and see if that helps/go further ?
com.giderosmobile.android.player.LuaException: assign to undeclared variable 'mysolve'
stack traceback:
[string "libs/strict.lua"]:28: in function <[string "libs/strict.lua"]:24>
[string "luabinding/compatibility.lua"]:69: in function require
[string "jsovle.lua"]:1: in function <[string "jsovle.lua"]:1>
at LUA.string_libsstrictlua24(string_libsstrict.lua:28)
at LUA.require(string_luabindingcompatibility.lua:69)
at LUA.string_jsovlelua1(string_jsovle.lua:1)
luaL_register(L, NULL, func_list);
after change to this, it will not exit on require "mysolve"
but when call mysolve.generate, it exits
com.giderosmobile.android.player.LuaException: [string "jsovle.lua"]:112: variable 'mysolve' is not declared
stack traceback:
[string "libs/strict.lua"]:37: in function <[string "libs/strict.lua"]:35>
[string "jsovle.lua"]:112: in function generate
[string "board.lua"]:91: in function newPuzzle
[string "board.lua"]:43: in function init
[string "luabinding/property.lua"]:75: in function __new
[string "luabinding/property.lua"]:82: in function new
[string "game.lua"]:30: in function addBoard
[string "game.lua"]:4: in function init
[string "luabinding/property.lua"]:75: in function __new
[string "luabinding/property.lua"]:82: in function new
[string "libs/scenemanager.lua"]:291: in function changeScene
[string "mainmenu.lua"]:79: in function onClick
[string "libs/button.lua"]:319: in function onMouseUp
at LUA.string_libsstrictlua35(string_libsstrict.lua:37)
at LUA.generate(string_jsovle.lua:112)
at LUA.newPuzzle(string_board.lua:91)
at LUA.init(string_board.lua:43)
at LUA.__new(string_luabindingproperty.lua:75)
at LUA.new(string_luabindingproperty.lua:82)
at LUA.addBoard(string_game.lua:30)
at LUA.init(string_game.lua:4)
at LUA.__new(string_luabindingproperty.lua:75)
at LUA.new(string_luabindingproperty.lua:82)
at LUA.changeScene(string_libsscenemanager.lua:291)
at LUA.onClick(string_mainmenu.lua:79)
at LUA.onMouseUp(string_libsbutton.lua:319)
It still exit on require "mysolve"
com.giderosmobile.android.player.LuaException: assign to undeclared variable 'myFirstPlugin'
#include "gideros.h"
#include "lua.h"
#include "lauxlib.h"
static int addTwoIntegers(lua_State *L)
{
//retrieve the two integers from the stack
int firstInteger = lua_tointeger(L, -1);
int secondInteger = lua_tointeger(L, -2);
int result = firstInteger + secondInteger;
//place the result on the stack
lua_pushinteger(L, result);
//one item off the top of the stack, the result, is returned
return 1;
}
static int loader(lua_State *L)
{
//This is a list of functions that can be called from Lua
const luaL_Reg functionlist[] = {
{"addTwoIntegers", addTwoIntegers}, {NULL, NULL}, };
luaL_register(L, "myFirstPlugin", functionlist);
//return the pointer to the plugin
return 1;
}
static void g_initializePlugin(lua_State* L)
{
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
lua_pushcnfunction(L, loader, "myFirstPlugin_init");
lua_setfield(L, -2, "mysolve");
lua_pop(L, 2);
}
static void g_deinitializePlugin(lua_State *L)
{ }
REGISTER_PLUGIN("Mysolve", "1.0")
Likes: Xman, MoKaLux
Likes: MoKaLux
On the other hand, when lua_regsiter is called with NULL, the global variable is not created at all, which your code seems to depend on.
Likes: Xman, MoKaLux
Likes: MoKaLux