Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

lua_call issues

This topic is 4871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to call a lua function within a C++ function but every time I put in lua_call it crashes the program, if I comment it out it works. I know I am calling a valid function and even with the simplest of functions it wont work (like ones that take no params and return no values) Is there something that would cause it to act this way? I am getting [Warning] `Lua' has incomplete type if its of any significance (Lua being a lua_State*) thx for the help =) EDIT: I am initalizing using and then deleting the lua_State in this function im not sure if this is good practice (should the lua_State be global)

Share this post


Link to post
Share on other sites
Advertisement
As I said to someone else, should you perhaps use lua_pcall instead of lua_call? That warning implies that you're passing around a pointer but your C++ file doesn't have access to the proper definition of lua_State, which is an issue if you need to construct or destroy it but then I think it wouldn't compile in the first place. To give more information we'd need to see more code though.

Share this post


Link to post
Share on other sites
Don't delete the lua state. Yes make/keep it global, ignore the fact that c-side lua functions have a parameter list "int (function name)(lua_State *lua). make your lua_State var global anyway, and don't ever delete it. It should be created and destroyed outside your lua calls

Share this post


Link to post
Share on other sites
quick question,
how come this doesnt work
function add()
TYPE, Height, Width = TABLE["1"]
Image_Path = "PNG/Nuetral/Infentry.PNG";
return TYPE, Image_Path, Height, Width;
end

function FUNCTION()
return "A", 7,7;
end

TABLE = {};

TABLE["1"] = FUNCTION;

but this does

function add()
TYPE, Height, Width = FUNCTION
Image_Path = "PNG/Nuetral/Infentry.PNG";
return TYPE, Image_Path, Height, Width;
end

function FUNCTION()
return "A", 7,7;
end

I figured that if TABLE["1"] = FUNCTION
then It would just return FUNCTION when I set things equal to it but it doesnt work. anyone know why?

Share this post


Link to post
Share on other sites
Rap. try entering your code into the lua interpreter. Both examples do what they're supposed to.
You are obviously starting to learn lua. Big suggestion, keep the compiled lua interpreter handy all the time so you can test code chunks and also to help learn the little things like the different ways you can reference arrays.

For example, I learned that I couldn't do
variable=nil and then
variable[1] = something
I had to do
variable = {} first
obviously you are already using that.

Did you know that you don't need to "numbers" that are array indicies?
infact, ex.
a['1'], and a[1] are completely different indicies. So unless you really wanted
TABLE["1"] to be a string type array index, just use numbers.

I hope you are enjoying learning such a fine language, I certainly love it!

ps. you know you never need to end a line with semicolons, they are only useful if you have line where you have more than one command such as
for i=1,5 do print('hello');print('what time is it?');print(i,"o'clock");end
I know most come from a C background, and sometimes I find myself about to press the ';' at the end of a lua line, but really your code will be easier to read without them

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!