[all] Problem with executeString


#1

I have a function defined in inbox.lua:
@
function UpdateInbox()
flux.printf(“UpdateInbox:”);
end
UpdateInbox()
@

I am calling DoFile from a separate lua thread like this:
CCLuaEngine::defaultEngine()->getLuaStack()->executeScriptFile(pathKey.c_str());

There is no error on the above call and “UpdateInbox:” is written to the debug output as expected.

The problem I am having is that when I do
cocos2d::CCLuaEngine::defaultEngine()->getLuaStack()->executeString("UpdateInbox()");
the function doesn’t seem to be defined. I get
PANIC: unprotected error in call to Lua API ([string "flux/strict.lua"]:30: attempt to index a nil value)
I have verified that both calls are made on the same stack. What am I missing? I am using threads, but AFAIK if the function should be defined if it is declared in a file that is executed on the same stack.


#2

How can I reapper this error?Can you give some easy code to make this error, thank you.


#3

Hi Sam,
I find that all I have to do is add a lua function:
@
function teststuff()
print(“test stuff!”)
end
@

And in C++:
@
CCLuaEngine::defaultEngine()->getLuaStack()->executeString(“teststuff()”);
@
and I will get
@
PANIC: unprotected error in call to Lua API ([string “flux/strict.lua”]:30: attempt to index a nil value)
@
Cheers,
Paul


#4

I should mention that I can call the same teststuff() method from lua. So I get the correct output if I put
@
teststuff()
@
right after I declare the function.
Thanks again.
p


#5

I think this error is because you don’t have the function to the state.If you should executeScriptFile before,then call executeString,it can work sucessful.


#6

I have narrowed it down further. I have created a file testy.lua that contains
@
function FooTest()
print(“Hi from FooTest”)
end
FooTest()
@

Then in my app delegate I call
@
CCLuaEngine::defaultEngine()->executeScriptFile(“scripts/testy.lua”);
CCLuaEngine::defaultEngine()->getLuaStack()->executeString(“FooTest()”);
@

I get the correct output on the first line, but I still get the same error message on the second:
@
Cocos2d: [LUA-print] Hi from FooTest
PANIC: unprotected error in call to Lua API ([string “flux/strict.lua”]:30: attempt to index a nil value)
@


#7

I have narrowed it down further. I have created a file testy.lua that contains
@
function FooTest()
print(“Hi from FooTest”)
end
FooTest()
@

Then in my app delegate I call
@
CCLuaEngine::defaultEngine()->executeScriptFile(“scripts/testy.lua”);
CCLuaEngine::defaultEngine()->getLuaStack()->executeString(“FooTest()”);
@

I get the correct output on the first line, but I still get the same error message on the second:
@
Cocos2d: [LUA-print] Hi from FooTest
PANIC: unprotected error in call to Lua API ([string “flux/strict.lua”]:30: attempt to index a nil value)
@


#8

I use the hellolua test case to reappear this error ,the code as follow:
@
std::string path = CCFileUtils::sharedFileUtils()>fullPathForFilename;
pEngine
>executeScriptFile(path.c_str());
pEngine->executeString(“FooTest()”);
@
The output as follow:
Cocos2d: [LUA-print] Hi from FooTest
Cocos2d: [LUA-print] Hi from FooTest

It did’t appear the error you said.Can you confirm you test code don’t contain the flux/strict.lua and can you clean your project first.


#9

Sorry for fading out on you there.
I tried taking out strict.lua and it does work. But strict.lua finds so many bugs that I would hate to have to take it out.
Any idea why strict.lua breaks here? The function is obviously defined.
It breaks here I am guessing because mt.__declared[n] returns false:
mt.__index = function (t, n) if not mt.__declared[n] and debug.getinfo(2, "S").what ~= "C" then error("variable '"..n.."' is not declared", 2) end return rawget(t, n) end
strict.lua since is pretty much quadruples my productivity so it would be nice to find a workaround. I would be fine with declaring certain functions with some sort of rawset or something. Unfortunately I don’t understand lua metatables :frowning: