lua-c++-connection

How to create table in table in Lua 5.1 using C-API?

北城以北 提交于 2019-12-06 12:00:37
问题 I need to create construction like this in Lua 5.1 C-API, not in Lua 5.2 and above a = {["b"] = {["c"] = {["d"] = {["e"] = "GOOD"}}}} print(a.b.c.d.e); Expected Result: GOOD Thanks for answers! 回答1: The Lua C API is stack based. That means that the behavior of most of the C API functions depends not only on the arguments given, but also on the contents of the Lua stack (which is part of the lua_State* variable commonly called L ). What a particular API function expects in terms of stack

How to create table in table in Lua 5.1 using C-API?

别说谁变了你拦得住时间么 提交于 2019-12-04 17:08:39
I need to create construction like this in Lua 5.1 C-API, not in Lua 5.2 and above a = {["b"] = {["c"] = {["d"] = {["e"] = "GOOD"}}}} print(a.b.c.d.e); Expected Result: GOOD Thanks for answers! The Lua C API is stack based. That means that the behavior of most of the C API functions depends not only on the arguments given, but also on the contents of the Lua stack (which is part of the lua_State* variable commonly called L ). What a particular API function expects in terms of stack contents and how it affects the elements of the stack, you'll have to look up in the Lua manual . Let's start

Lua and C++: separation of duties

♀尐吖头ヾ 提交于 2019-12-03 16:58:26
问题 Please help to classify ways of organizing C++/Lua game code and to separate their duties. What are the most convenient ways, which one do you use? For example, Lua can be used for initializing C++ objects only or at every game loop iteration. It can be used for game logic only or for graphics, too. Some game engines provide full control to all subsytems from scripts! I really do not like this approach (no separation at all). Is it a good idea to implement all game objects (npc, locations) as

Lua and C++: separation of duties

若如初见. 提交于 2019-12-03 06:02:23
Please help to classify ways of organizing C++/Lua game code and to separate their duties. What are the most convenient ways, which one do you use? For example, Lua can be used for initializing C++ objects only or at every game loop iteration. It can be used for game logic only or for graphics, too. Some game engines provide full control to all subsytems from scripts! I really do not like this approach (no separation at all). Is it a good idea to implement all game objects (npc, locations) as Lua tables without C++ objects? Or it is better to mirror them (Lua tables to control C++ objects)? Or

Lua, game state and game loop

北城以北 提交于 2019-12-03 03:45:30
问题 Call main.lua script at each game loop iteration - is it good or bad design? How does it affect on the performance (relatively)? Maintain game state from a . C++ host-program or b . from Lua scripts or c . from both and synchronise them? (Previous question on the topic: Lua and C++: separation of duties ) (I vote for every answer. The best answer will be accepted.) 回答1: The best thing about lua is that it has a lightweight VM, and after the chunks get precompiled running them in the VM is

Lua, game state and game loop

自闭症网瘾萝莉.ら 提交于 2019-12-02 17:11:55
Call main.lua script at each game loop iteration - is it good or bad design? How does it affect on the performance (relatively)? Maintain game state from a . C++ host-program or b . from Lua scripts or c . from both and synchronise them? (Previous question on the topic: Lua and C++: separation of duties ) (I vote for every answer. The best answer will be accepted.) The best thing about lua is that it has a lightweight VM, and after the chunks get precompiled running them in the VM is actually quite fast, but still not as fast as a C++ code would be, and I don't think calling lua every rendered

luaL_dostring puts nothing on the stack?

跟風遠走 提交于 2019-12-01 21:06:13
问题 I'm trying to learn the basics of interfacing Lua with C++, but I've run into a problem. I want to call a function that returns a string, and then work with the string on the C++ side, but luaL_dostring seems to put nothing on the Lua stack. Even a simple test doesn't seem to work properly: lua_State* lua = lua_open(); luaL_openlibs(lua); //Test dostring. luaL_dostring(lua, "return 'derp'"); int top = lua_gettop(lua); cout << "stack top is " <<top << endl; //Next, test pushstring. lua

luaL_dostring puts nothing on the stack?

廉价感情. 提交于 2019-12-01 19:01:43
I'm trying to learn the basics of interfacing Lua with C++, but I've run into a problem. I want to call a function that returns a string, and then work with the string on the C++ side, but luaL_dostring seems to put nothing on the Lua stack. Even a simple test doesn't seem to work properly: lua_State* lua = lua_open(); luaL_openlibs(lua); //Test dostring. luaL_dostring(lua, "return 'derp'"); int top = lua_gettop(lua); cout << "stack top is " <<top << endl; //Next, test pushstring. lua_pushstring(lua, "derp"); top = lua_gettop(lua); cout << "stack top is " << top << endl; Output: stack top is 0