Hello!
Is it possible to pass an array to a plugin function?
Can a plugin function also return an array to Hollywood?
A simple C ++ example would be nice.
Greetings, Michael
Array and plugin functions
Array and plugin functions
PostgreSQL-Library V1.0 Final: https://forum.amiga-resistance.info/vie ... =38&t=3591
- airsoftsoftwair
- Posts: 5673
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Array and plugin functions
Sure, this is possible, e.g something like this.
MyFunc() expects a table containing only numbers (in linear order) in argument 1. It will print all those numbers to the console.
Code: Select all
static int MyFunc(lua_State *L)
{
int n, done;
for(n = 0, done = 0; !done; n++) {
lua_rawgeti(L, 1, n);
if(lua_isnil(L, -1)) done = 1; else printf("Value at index %d is %.14g\n", n, lua_tonumber(L, -1));
lua_pop(L, 1);
}
return 0;
}
Re: Array and plugin functions
How do I declare lua_isnil, lua_tonumber, lua_pop in the C++ Header?
They do not seem to belong to LuaBase.
It was easy with lua_rawgeti.
The following entry in the header worked:
They do not seem to belong to LuaBase.
It was easy with lua_rawgeti.
The following entry in the header worked:
Code: Select all
#define lua_rawgeti hwcl->LuaBase->lua_rawgeti
PostgreSQL-Library V1.0 Final: https://forum.amiga-resistance.info/vie ... =38&t=3591
- airsoftsoftwair
- Posts: 5673
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Array and plugin functions
lua_tonumber() is part of LuaBase. The other two are macros and are defined like this in Lua 5.0.2:
Be careful to use Lua 5.0.2 when importing macros because that's what Hollywood uses. Newer versions can be incompatible with 5.0.2.
Code: Select all
#define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL)
#define lua_pop(L,n) lua_settop(L, -(n)-1)