Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
my plugin not work in current Gideros release. — Gideros Forum

my plugin not work in current Gideros release.

XmanXman Member
edited December 7 in General questions
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);
}


Likes: MoKaLux

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • hgy29hgy29 Maintainer
    Hi @Xman,
    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 ?
    	lua_newtable(L);
    	luaL_register(L, NULL, func_list);
  • XmanXman Member

    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)
  • XmanXman Member
    edited December 8
    lua_newtable(L);
    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)
  • XmanXman Member
    ndk version is 29.0.14033849
  • XmanXman Member
    even when I change my plugin to this demo in https://wiki.gideros.rocks/index.php/Extend_your_application_with_plugins,
    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")
  • hgy29hgy29 Maintainer
    Accepted Answer
    Ah, perhaps the problem is with strict.lua, can you try to disable it ?

    Likes: Xman, MoKaLux

    +1 -1 (+2 / -0 )Share on Facebook
  • XmanXman Member
    I really appreciate your help.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    Accepted Answer
    I think what happens is due to luau. When you call lua_register with a table name, luau native code will try to create the corresponfing global variable, which will be caught by strict.lua mt.__newindex function, and for some reason 'w' (what) in that function is not 'C'. It would be interesting to know what it was.

    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

    +1 -1 (+2 / -0 )Share on Facebook
  • XmanXman Member
    Thanks for your explanation.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.