1

Topic: Context - a C ++-> Lua-> With ++ and still questions

Hello! I build in here Lua the program, basically, all simply, but did not understand, how to me to transfer any context in the Cs ++ functions. luaState = luaL_newstate (); lua_setcontext (luaState, (void *) &someMyContext);//required//... int my_lua_cpp_func (lua_State *lua) {CMyContext *pMyContext = (CMyContext *) lua_getcontext (lua);//required//do something with context}//... lua_register (luaState, "my_lua_cpp_func", &my_lua_cpp_func); the Essence such that in mine sishnye/pljusovye function needs to transfer in addition something, depending on  Lua. While at me than one is not planned  more, and all can be made through global variables, but it at all is not pleasant to me. In Windows for all  it is possible to specify LPVOID lpvParam where it is possible on this to transfer the pointer, or still something useful. I search for something similar. Yet did not understand, how it to make, prompt where to esteem?  Forgot the second question did not understand how to restrict set of used Lua-functions. In my scripts, except mathematical functions, anything else it is not necessary for me, moreover, even it is counter-indicative. How it to restrict?

2

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, Marty, you wrote: M> the Essence such that in mine sishnye/pljusovye function needs to transfer in addition something, depending on  Lua. While at me than one is not planned  more, and all can be made through global variables, but it at all is not pleasant to me. In LUA there are global variables in which it is possible to write down on the side With ++ anything you like. On side LUA to transfer this business it is reverse through arguments my_lua_cpp_func

3

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, Marty, you wrote: M> the Essence such that in mine sishnye/pljusovye function needs to transfer in addition something, depending on  Lua. While at me than one is not planned  more, and all can be made through global variables, but it at all is not pleasant to me. In the register it is possible to thrust. https://www.lua.org/pil/27.3.1.html M>  Forgot the second question M> did not understand how to restrict set of used Lua-functions. In my scripts, except mathematical functions, anything else it is not necessary for me, moreover, even it is counter-indicative. How it to restrict? Probably for each version to saw the luaL_openlibs And generally, look aside selene. If anything special it is not planned, it strongly facilitates life.

4

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, drVan, you wrote: M>> the Essence such that in mine sishnye/pljusovye function needs to transfer in addition something, depending on  Lua. While at me than one is not planned  more, and all can be made through global variables, but it at all is not pleasant to me. V> in LUA there are global variables in which it is possible to write down on the side With ++ anything you like. On side LUA to transfer this business it is reverse through arguments my_lua_cpp_func It is one of the most bad methods, . 1) from the Lua-party unless it is impossible to re-record such global variable? 2) on the Lua-party it is necessary to oblige the user always to set the first argument a context that looks overloading for the user who writes a script, in comparison with normal Lua. Better in  parts to get global variable and to rejoice that plural  Lua are not necessary in the given task

5

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, andrey.desman, you wrote: M>> the Essence such that in mine sishnye/pljusovye function needs to transfer in addition something, depending on  Lua. While at me than one is not planned  more, and all can be made through global variables, but it at all is not pleasant to me. AD> in the register it is possible to thrust. AD> https://www.lua.org/pil/27.3.1.html Hm, is idea. If still to chop off for the user (the writer of a script) registry access, quite working variant. M>>  Forgot the second question M>> did not understand how to restrict set of used Lua-functions. In my scripts, except mathematical functions, anything else it is not necessary for me, moreover, even it is counter-indicative. How it to restrict? AD> probably for each version to saw the luaL_openlibs It should be easier. I already Lua built in somehow the programs. And in that project, on idea, it was not necessary anything from the built in Lua-functions, I there looked, is similar that indeed. Like, Lua-builtins it is necessary most to add/register, and like (it already from area of conjectures) could be added not separately somehow somehow, and packs - type to add math. *, os. *, io.* etc. I will dig out it, simply thought, who can reminds where to dig Thought, to ask it turns out AD> And generally faster, look aside selene. If anything special it is not planned, it strongly facilitates life. github.com someone's at me at all

6

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, Marty, you wrote: M> Hm, is idea. If still to chop off for the user (the writer of a script) registry access, quite working variant. So it also does not have access there. On design. M> it should be easier. I already Lua built in somehow the programs. And in that project, on idea, it was not necessary anything from the built in Lua-functions, I there looked, is similar that indeed. Like, Lua-builtins it is necessary most to add/register, and like (it already from area of conjectures) could be added not separately somehow somehow, and packs - type to add math. *, os. *, io.* etc. I will dig out it, simply thought, who can reminds where to dig Thought, to ask it turns out Earlier it was possible to load  separately faster, were  for this purpose. Now it is necessary to do by pens. In the same file : ** If you embed Lua in your program and need to open the standard ** libraries, call luaL_openlibs in your program. If you need a ** different set of libraries, copy this file to your project and edit ** it to suit your needs. AD>> And generally, look aside selene. If anything special it is not planned, it strongly facilitates life. M>github.com someone's at me at all  Transits

7

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, Marty, you wrote: V>> In LUA there are global variables in which it is possible to write down on the side With ++ anything you like. On side LUA to transfer this business it is reverse through arguments my_lua_cpp_func M> It is one of the most bad methods, . 1) from the Lua-party unless it is impossible to re-record such global variable? 2) on the Lua-party it is necessary to oblige the user always to set the first argument a context that looks overloading for the user who writes a script, in comparison with normal Lua. It is possible to read Global variables LUA and on the side With ++

8

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, drVan, you wrote: V>>> In LUA there are global variables in which it is possible to write down on the side With ++ anything you like. On side LUA to transfer this business it is reverse through arguments my_lua_cpp_func M>> It is one of the most bad methods, . 1) from the Lua-party unless it is impossible to re-record such global variable? 2) on the Lua-party it is necessary to oblige the user always to set the first argument a context that looks overloading for the user who writes a script, in comparison with normal Lua. V> it is possible to read Global variables LUA and on the side With ++ To me it is necessary to restrict Lua - including, and access (at least on record) to global variables. The script should have access to math, to my functions, to some global variables, and all

9

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, Marty, you wrote: M> Hello!... M> an essence such that in mine sishnye/pljusovye function needs to transfer in addition something, depending on  Lua. While at me than one is not planned  more, and all can be made through global variables, but it at all is not pleasant to me. M> in Windows for all  it is possible to specify LPVOID lpvParam where it is possible on this to transfer the pointer, or still something useful. I search for something similar. Yet did not understand, how it to make, prompt where to esteem? Normally use userdata https://www.lua.org/pil/28.1.html Still it is possible closure function  https://www.lua.org/pil/27.3.3.html M> did not understand how to restrict set of used Lua-functions. In my scripts, except mathematical functions, anything else it is not necessary for me, moreover, even it is counter-indicative. How it to restrict? http://lua-users.org/wiki/AlternativeModuleDefinitions there there is a variant 7 with ENV it restricts visibility of units. It is possible to remove similarly superfluous of visibility area at creation luastate to leave only the necessary.

10

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, Marty, you wrote: All thanks. Like understood. M> an essence such that in mine sishnye/pljusovye function needs to transfer in addition something, depending on  Lua. While at me than one is not planned  more, and all can be made through global variables, but it at all is not pleasant to me. For context transmission how much I understood, it is necessary to use lua_getextraspace. There by default there is a place under void *, and there it is possible to write down the pointer. Correct, if it is not right M> In Windows for all  it is possible to specify LPVOID lpvParam where it is possible on this to transfer the pointer, or still something useful. I search for something similar. Yet did not understand, how it to make, prompt where to esteem? M>  Forgot the second question M> did not understand how to restrict set of used Lua-functions. In my scripts, except mathematical functions, anything else it is not necessary for me, moreover, even it is counter-indicative. How it to restrict? Here yes, the most simple method is to correct luaL_openlibs, more truly, an array static const luaL_Reg loadedlibs []

11

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, Marty, you wrote: M> For context transmission how much I understood, it is necessary to use lua_getextraspace. There by default there is a place under void *, and there it is possible to write down the pointer. Correct, if it is not right M>> In Windows for all  it is possible to specify LPVOID lpvParam where it is possible on this to transfer the pointer, or still something useful. I search for something similar. Yet did not understand, how it to make, prompt where to esteem? Above already about UserData wrote. Somehow so://static function, is added in global  at creation LuaVM, for example with name NewMyObject. int MyObject:: New (lua_State *L) {void *pObjectPlace = lua_newuserdata (L, sizeof (MyObject)); MyObject* pNewObject = new (pObjectPlace) MyObject; UNREFERENCED_PARAMETER (pNewObject); luaL_getmetatable (L, MY_OBJECT_METATABLE); lua_setmetatable (L,-2); return 1;} ...//static function, is caused once at initialization LUA of the machine int MyObject:: CreateMeta (lua_State *L) {//a meta-table Type:////__ index//|//| - methods////__ gc//luaL_newmetatable (L, MY_OBJECT_METATABLE); lua_pushstring (L, "__ index"); lua_newtable (L); static const struct luaL_Reg myobj [] = {{"MethodName1", MyObject:: Method1}, {"MethodName2", MyObject:: Method2}, {"MethodName3", MyObject:: Method3}, {NULL, NULL},};//It is added fields-metdoy in the table "__ index" luaL_register (L, NULL, myobj);//we Add a field-table "__ index" in the meta-table lua_settable (L,-3);//we Add a field "__ gc" in the meta-table to control corrupting of objects lua_pushstring (L, "__ gc"); lua_pushcfunction (L, MyObject:: gc_Close); lua_settable (L,-3); return 1;} ... int MyObject:: Method1 (lua_State *L) {//Almost that strict typification - any parameter of not having just the same metatable not //also can be made analog of static functions: whether we check the first parameter this (i.e. the user type, through lua_touserdata)//is - if the method is caused through var:method - that in the first parameter implicitly will be transferred this, we receive on it the pointer through check//- if the method is caused as var.method - that the immediate parameter list will be transferred, we receive them as is. MyObject *pObject = reinterpret_cast <MyObject *> (luaL_checkudata (L, 1, MY_OBJECT_METATABLE));//error handling can be made and bar none, for example so://if function does not return true - means in the second parameter the error status code if is returned (! Success) {lua_pushboolean (L, 0); lua_pushinteger (L, ErrorCode); return 2;} lua_pushboolean (L, 1); return 1;} ...//static function, is caused by a garbage collector, gives us chance to lead necessary  int MyObject:: gc_Close (lua_State *L) {MyObject *pObject = reinterpret_cast <MyObject *> (luaL_checkudata (L, 1, MY_OBJECT_METATABLE)); pObject-> ~ MyObject (); return 0;} M>>  Forgot the second question M>> did not understand how to restrict set of used Lua-functions. In my scripts, except mathematical functions, anything else it is not necessary for me, moreover, even it is counter-indicative. How it to restrict? M> here yes, the most simple method is to correct luaL_openlibs, more truly, an array static const luaL_Reg loadedlibs [] so.

12

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, IID, you wrote: M>> For context transmission how much I understood, it is necessary to use lua_getextraspace. There by default there is a place under void *, and there it is possible to write down the pointer. Correct, if it is not right M>>> In Windows for all  it is possible to specify LPVOID lpvParam where it is possible on this to transfer the pointer, or still something useful. I search for something similar. Yet did not understand, how it to make, prompt where to esteem? IID> above already about UserData wrote. I meant a certain global context of type CLuaHost *, instead of the pointer on classes which I create in in the functions. Though also it too is necessary. IID> somehow so: And it is possible to describe words sequence? And that so like clear but to recreate it did not turn out. Especially, also out-of-date functions you use By the way, you like forgot to anchor function of removal. But I like found, she should be added with a name "__ gc"

13

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, Marty, you wrote: M> And it is possible to describe words sequence? And that so like clear but to recreate it did not turn out. Especially, also out-of-date functions you use is not higher annual prescription. And a little that changes in lua. Handling ellipsis was the last significant change on my storage. M> By the way, you like forgot to anchor function of removal. But I like found, she should be added with a name "__ gc" Make ctrl+f on my comment, you will be surprised...

14

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, IID, you wrote: M>> And it is possible to describe words sequence? And that so like clear but to recreate it did not turn out. Especially, also out-of-date functions you use IID> is not higher annual prescription. And a little that changes in lua. Handling ellipsis was the last significant change on my storage. luaL_register, as well as luaL_openlib in which this macro is uncovered, in the documentation to Lua 5.3 already miss M>> By the way, you like forgot to anchor function of removal. But I like found, she should be added with a name "__ gc" IID> Make ctrl+f on my comment, you will be surprised... Yes, something looked through. In one of examples which I , "__ gc" go in the table with remaining methods.

15

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, IID, you wrote: Set a compatibility macro, like your version gathered and even poorly poorly works. But there was an inconvenient nuance - copy creation. Now I create separate global function, but generally here create objects so: local foo = Foo.new ("fred") It would be desirable as. There all functions are fallen down in one heap (, it there and "__ gc" in the same heap with remaining functions) so: luaL_Reg sFooRegs [] = {{"new", l_Foo_constructor}, {"add", l_Foo_add}, {"__ gc", l_Foo_destructor}, {NULL, NULL}}; At me on "f = Foo.new ()"produces"attempt to index a nil value (global ' Foo ')" Tried to add your code in such line: lua_setglobal (luaState, "Foo"); Then produces:" attempt to call a nil value (field ' new ') "By the way, I yet did not understand, whence yours" int MyObject:: CreateMeta (lua_State *L) "am caused? It like is issued as"C"- the function caused from Lua, but on idea, it should pens from a C/C ++ the code be caused before performance of Lua-scripts?

16

Re: Context - a C ++-> Lua-> With ++ and still questions

Hello, Marty, you wrote: M> Set a compatibility macro, like your version gathered and even poorly poorly works. But there was an inconvenient nuance - copy creation. Now I create separate global function, but generally here create objects so: M> local foo = Foo.new ("fred") M> It would be desirable as.  your code for "__ gc", instead of "__ gc" interposed "new", left "lua_setglobal (luaState," Foo ");" - and like all works as it is necessary. How much it is correct, but like works. Still for a set conversion to a line to make, searched "__ tostring", but did not find. Found "__ concat" - like similar on required, but here, it is necessary to try