• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

Lua require function

cortomaltese_mf

New Member
Joined
Feb 12, 2007
Messages
2 (0.00/day)
Hello there,
I use Lua script language, either calling lua scripts from C++ or calling C/C++ functions from lua. Im running lua version 5.0.2.
I'm using the require function from a C program to load lua functions
and evrything seems to work fine.
As I read,
<<require keeps a table with the names of all loaded files. If a
required file is already in the table, require simply returns. So if I
overwrite a lua file containing a function, to get the new version I
must restart the program.
As I read in the Lua manual, after a successful require"foo",
_LOADED["foo"] will not be nil. If you then assign nil to
_LOADED["foo"], a subsequent require"foo" will run the file again.>>

With this in mind, my aim was to do something like
_LOADED[funcname] = nil everytime I overwrite the file.


My problem is that I'm not able to access this table from my C
program, i.e. I do something like
lua_getglobal(L, "_LOADED");
if (!lua_istable(L, -1))
{printf"_LOADED is not a valid table"); exit(0);}
n = lua_getn(L, -1); n IS ALWAYS ZERO !!!!!!


I try to read my element in the following way:


lua_getglobal(L, "_LOADED");
if (!lua_istable(L, -1))
{printf"_LOADED is not a valid table"); exit(0);}
lua_pushstring(L, funcname);
lua_gettable(L, -2);
if (!lua_isstring(L, -1))
printf("invalid component in _LOADED");
else
myname = lua_tostring(L, -1);
lua_pop(L, 1);


But I always get the message invalid component.


I run the require function before so I expected to find something in
the _LOADED table.
Can anybody please help me to change the _LOADED[] table values from
my C program.


Thank you in advance
 
But I always get the message invalid component.

On a guess? Does this LUA stuff use any type of OLEServer/ActiveX componentry? If so, judging by the message, it may not be registered...

e.g./i.e.-> regsvr32.exe {componentname}

* What component (DLL/OCX etc.) that is? I have NO idea... just taking a guess here, but, hope it helps YOU 'zero-in' on what the problem MAY be... because it sounds like that to me, like it's trying to make a function call to some library & is unable to marshal it, because it's just not registered via a CLSID.

APK
 
Lua _LOADED table

Thank you Alec, unfortunately this is not the case, it doesn't use ActveX objects.
Marco
 
Thank you Alec, unfortunately this is not the case, it doesn't use ActveX objects.
Marco

No DLL's either? It does sound as if it cannot reference some object/class that would be called from a lib of somekind, but... I don't use that toolset.

:(

* Just guessing, but unfortunately, not right apparently this round... oh well!

APK

P.S.=> Good luck though... apk
 
Back
Top