Jump to content
  • Advertisement
Sign in to follow this  

Get data into C++ from lua table

This topic is 3994 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

I can get a global int into C++, but having trouble with tables: settings.lua reads: ------------------ testValue = 100 video = { fullscreen=0, [other-video-stuff] } audio = { [audio-settings] } player = { etc } C++ code that can get testValue: -------------------------------- luaL_loadfile(lua_state, "settings.lua"); lua_pcall(lua_state, 0,0,0); lua_getglobal(lua_state, "testValue"); int t = lua_tonumber(lua_state,-1); std::cout << "t=" << t << ".\n"; How do I get the number video.fullscreen into t?

Share this post


Link to post
Share on other sites
Advertisement
try:


lua_pushstring( lua_state, "video" );
lua_gettable( lua_state, LUA_GLOBALSINDEX );
lua_pushstring( lua_state, "fullscreen" );
lua_gettable( lua_state, -2 );

int iFullscreen = (int)lua_tonumber( lua_state, -1 );

// clean up lua stack
lua_pop( lua_state, lua_gettop( lua_state ) );

Share this post


Link to post
Share on other sites
Hey thanks, that did the trick!
app now picks screen mode based on lua text file.

CreateWindowEx:
(fullscreen ? WS_POPUP|WS_EX_TOPMOST : WS_OVERLAPPEDWINDOW)

D3DPRESENT_PARAMETERS
screen_presentation.Windowed = !fullscreen

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!