Comments (2)
It would be nice to know what you are actually trying with this. There might be alternate existing solutions to achieve what you want.
Some of the problems you are hitting may be the following:
_G
A global variable (not a function) that holds the global environment (see ยง2.2). Lua itself does not use this variable; changing its value does not affect any environment, nor vice versa.
__index: The indexing access operation table[key]. This event happens when table is not a table or when key is not present in table.
Additionally, you are trying to use an object as a metatable, which may not be supported.
So maybe avoid using the usertype completely. Simply use normal tables for everything.
For example, probably want to change globals[sol::metatable_key] = NoopMetatable{};
to actually refer to a table.
Could you maybe tell what kind of errors and issues you are getting? Maybe some examples of how you try to invoke things in the global environment?
from sol2.
It would be nice to know what you are actually trying with this. There might be alternate existing solutions to achieve what you want.
I have a method that I inject to my script:
local my_var = input_vars.register("My variable", input_vars.types.String);
During actual execution of script, this method will read the "My variable" from some place in my game engine and provide it to the script. However, I have another step that is before the execution of the script -- in my game engine's editor. The idea is that, if I load this script into my editor, my editor evaluates this script with a different logic for input_vars.register
-- instead of reading the runtime data for the script, it will automatically create UI controls in the editor that allows the user of the editor to store variables for the script. For example, the following script:
local value = input_vars.register('name', input_vars.types.AssetPrefab)
Creates an input that allows drag and dropping an asset that is available from the script:
This part works great with no issues. But imagine a scenario where a script uses a lot of APIs:
local value = input_vars.register('name', input_vars.types.AssetPrefab)
entity.animator:trigger("RunAnimation")
logger.debug("Debug logs")
game.on_update:connect(function(dt)
print('Update called')
end)
local command = entity.input:get_command("Jump")
local value = entity.input:get_value_boolean(command)
existing_entity = entity_query:get_first_entity_by_name("My entity name")
new_entity = entity_spawner:spawn_empty()
The editor only needs to evaluate input_vars.register('name', input_vars.types.AssetPrefab)
and ignore everything else. This is where I want to make it so that anything other than input_vars
global variable returns an empty table where every function and value returns a recursive table that does nothing. This way, whatever the developer provides will not do anything. To achieve this, this is what I am currently doing:
sol::state state;
// Create usertypes
NoopMetatable::create(state);
InputVars::create(state);
state["entity"] = NoopMetatable{};
state["entity_query"] = NoopMetatable{};
state["entity_spawner"] = NoopMetatable{};
state["logger"] = NoopMetatable{};
state["ui"] = NoopMetatable{};
state["table"] = NoopMetatable{};
state["game"] = NoopMetatable{};
state["input_vars"] = InputVars{};
I want to automate this part in a way that any field that is not input_vars
is always noop.
Could you maybe tell what kind of errors and issues you are getting? Maybe some examples of how you try to invoke things in the global environment?
I am getting no errors. It is just the environment data that I set just do not get applied.
from sol2.
Related Issues (20)
- Segfault from protected_function args push HOT 2
- std::terminate called on attempting to index a nil value HOT 2
- Doesn't build with Clang 18.1.0 HOT 9
- Not able to build with CMake HOT 3
- How to pass Lua Closures into C++ Functions in Sol3 ? HOT 4
- Test failure on x86
- Custom module loaders not working? HOT 1
- A const C++ container can be modified in Lua (want it to be truly const)
- Compilation Error when Member Variables set in new_usertype. HOT 1
- A bunch of errors when using usertypes HOT 1
- Is it possible to have out params / replace type and data referenced by sol::object? HOT 2
- Passing nil as userdata to C++ to reset a variable HOT 3
- On MSVC std::filesystem::path cannot be used as Lua type HOT 1
- Crash during destruction when using meta_function::new_index and coroutines
- Accessing table field with the wrong user type causes a segmentation fault
- Cannot directly bind b2Vec2 to a table entry HOT 1
- SOL_BASE_CLASSES / SOL_DERIVED_CLASSES should be mentioned in the documentation
- Generating definition files
- Why sol3 is slower than Luabridge3 when both using LuaJIT, HOT 1
- add_package_loader without lua_CFunction
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sol2.